#include "tablestruct.h"

CTableStruct::CTableStruct()
{
	m_uOp	= 0;
	m_uSave = 0;
}
CTableStruct::~CTableStruct()
{

}
std_method_impl CTableStruct::SetRecord(const FieldSturct& field)
{
	//logi("name=>%s,type=>%s,size=>%u,index =>%u",
	//	field.name,field.type,field.size,field.index);

	rc_assert(field.name[0] != 0, E_FAIL)
	rc_assert(field.type[0] != 0, E_FAIL)

	m_vecTableFields.push_back(field);

	return S_OK;
}
std_method_impl CTableStruct::GetRecord(UINT loop, FieldSturct* field)
{
	rc_assert((loop >= 0 && loop < m_vecTableFields.size()), E_FAIL)

	s_memcpy(field->name, m_vecTableFields[loop].name, FIELD_NAME_LEN);
	s_memcpy(field->type, m_vecTableFields[loop].type, FIELD_TYPE_LEN);
	field->size = m_vecTableFields[loop].size;
	field->index = m_vecTableFields[loop].index;
	

	return S_OK;
}
std_method_impl CTableStruct::GetAllRecord(FieldSturct fields[], UINT Count)
{
	UINT uloop = 0;
	for (uloop = 0; uloop < Count; uloop++)
	{
		s_memcpy(fields[uloop].name, m_vecTableFields[uloop].name, FIELD_NAME_LEN);
		s_memcpy(fields[uloop].type, m_vecTableFields[uloop].type, FIELD_TYPE_LEN);
		fields[uloop].size = m_vecTableFields[uloop].size;
		fields[uloop].index = m_vecTableFields[uloop].index;
	}
	return S_OK;
}
std_method_impl CTableStruct::GetFieldsCount(UINT &count)
{
	count = m_vecTableFields.size();
	return S_OK;
}
std_method_impl CTableStruct::GetTableName(LPSTR name)
{
	rc_assert(name != NULL, E_FAIL)
	s_memcpy(name, m_strTableName.c_str(), FIELD_NAME_LEN);
	return S_OK;
}
std_method_impl CTableStruct::SetTableName(LPCSTR name)
{
	m_strTableName.clear();
	m_strTableName.append(name);

	return S_OK;
}
std_method_impl CTableStruct::SetKeyValue(LPCSTR name, UINT op)
{
	if (s_stricmp(Rule_Op, name) == 0)
	{
		m_uOp = op;
	}
	else if (s_stricmp(Rule_Save, name) == 0)
	{
		m_uSave = op;
	}
	return S_OK;
}
std_method_type_impl(UINT) CTableStruct::IsExist()
{
	return m_uSave;
}
std_method_type_impl(UINT) CTableStruct::GetOp()
{
	return m_uOp;
}